package com.tgy.clickhouse.config;

import com.tgy.clickhouse.datasource.AIopsDynamicDatasource;

public class RoutingDataSourceContext {

    static final ThreadLocal<String> threadLocalDataSourceKey = new ThreadLocal<>();

    /**
     * 设置默认得数据源为MYSQL 1 的，不用注解自动执行，
     * 其余两个需要注解
     */
    public static String getDataSourceRoutingKey() {
        String key = threadLocalDataSourceKey.get();
        return key == null ? AIopsDynamicDatasource.MYSQL_DATASOURCE : key;
    }


    /**
     * 注解的时候就会把数据源给指定进去了
     */
    public static void RoutingDataSourceContext(String key) {
        threadLocalDataSourceKey.set(key);
    }

    public static void close() {
        threadLocalDataSourceKey.remove();
    }
}
